const webpack = require('webpack'),
  path = require('path'),
  autoprefixer = require('autoprefixer'),
  webpackConfig = require('./config.base'),
  CompressionWebpackPlugin = require('compression-webpack-plugin'),
  config = require('./const')

webpackConfig.module.rules.push({
  test: /\.css$/,
  use: ['style-loader', 'css-loader', 'postcss-loader']
})

webpackConfig.module.rules.push({
  test: /\.scss$/,
  use: ['style-loader', 'css-loader', 'autoprefixer-loader', 'sass-loader?compress=true']
})

webpackConfig.module.rules.push({
  test: /\.(js|jsx)$/,
  exclude: /node_modules/,
  loader: 'babel-loader',
  options: {
    presets: ['es2015', 'react', 'stage-0'],
    plugins: ['transform-runtime', 'add-module-exports', 'transform-decorators-legacy'],
    cacheDirectory: true
  }
})

webpackConfig.plugins.push(
  new webpack.DefinePlugin({'process.env': {NODE_ENV: JSON.stringify('production')}})
)

webpackConfig.plugins.push(
  new webpack.optimize.UglifyJsPlugin({
    comments: false,
    compress: {warnings: false}
  })
)

webpackConfig.plugins.push(
  new CompressionWebpackPlugin({
    asset: '[path].gz[query]',
    algorithm: 'gzip',
    test: new RegExp(
        '\\.(js|css)$'
    ),
    threshold: 10240,
    minRatio: 0.8
  })
)

module.exports = webpackConfig
